<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div style="height: 4000px"></div>
    <img
      data-src="https://yjy-oss-files.oss-cn-zhangjiakou.aliyuncs.com/tuxian/popular_1.jpg"
      alt=""
    />
    <script>
      const img = document.querySelector('img')
      const observer = new IntersectionObserver(([{ isIntersecting }]) => {
        console.log(isIntersecting)
        if (isIntersecting) {
          // 停止观察
          observer.unobserve(img)
          img.src = img.dataset.src
        }
      })
      observer.observe(img)
    </script>
  </body>
</html>
